package pl.edu.agh.anomalyids.lerad.aspect.implementation;

import pl.edu.agh.anomalyids.lerad.aspect.AbstractAspect;
import pl.edu.agh.anomalyids.lerad.aspect.enums.AspectType;
import pl.edu.agh.anomalyids.lerad.aspect.enums.Match;
import pl.edu.agh.anomalyids.network.Packet;
import pl.edu.agh.anomalyids.network.Packet.Protocol;
import pl.edu.agh.anomalyids.network.header.Header;
import pl.edu.agh.anomalyids.network.header.impl.ICMPHeader;

public class TypeIcmpAspect extends AbstractAspect<Integer> {

	private static final long serialVersionUID = -4590085603103679504L;

	public TypeIcmpAspect(Integer type) {
		super(AspectType.ICMPTYPE);
		this.values.add(type);
	}

	@Override
	public String toString() {
		return getData().toString();
	}

	@Override
	public Match packetMatchesAspect(Packet packet) {
		Header header = packet.getProtocols().get(Protocol.ICMP);
		if (header != null) {
			ICMPHeader icmp = (ICMPHeader) header;
			if (validate(icmp.getType())) {
				return Match.SAME;
			} else {
				return Match.DIFFER;
			}
		} else {
			return Match.UNKNOWN;
		}
	}

}
